home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Games / AGA / Shoot / Source / viewilbm.c < prev   
Encoding:
C/C++ Source or Header  |  1998-06-24  |  4.4 KB  |  263 lines

  1. #include <stdio.h>
  2. #include <intuition/intuition.h>
  3. #include <graphics/gfxbase.h>
  4. #include <graphics/sprite.h>
  5. #include <graphics/gels.h>
  6. #include <exec/types.h>
  7. #include <exec/memory.h>
  8. #include <libraries/dos.h>
  9. #include "shoot.h"
  10.  
  11. extern struct ViewPort my_view_port;
  12. extern struct BitMap my_bit_map;
  13.  
  14. struct FileHandle *tbild;
  15.  
  16. UBYTE picture[128];
  17. long int chunksize;
  18. int bodygot;
  19.  
  20. unsigned int chunksread;
  21.  
  22. UWORD width, height;
  23. int bytezeile, ncol, farben;
  24.  
  25. BYTE depth, compr, aspx, aspy;
  26.  
  27. ULONG camg;
  28. int bprow, bytezscreen;
  29.  
  30. BYTE colors[ 256*4 ];
  31.  
  32. int line, plane;
  33.  
  34. void iffbmhd( void )
  35. {
  36.     chunksread = chunksread | 1;
  37.  
  38.     if( Read( tbild, &width, 2 ) != 2 )
  39.     {    
  40.         printf("Read error bmhd\n");
  41.     }
  42.     if( Read( tbild, &height, 2 ) != 2 )
  43.     {    
  44.         printf("Read error bmhd\n");
  45.     }
  46.     if( Read( tbild, &picture, 4 ) != 4 )
  47.     {    
  48.         printf("Read error bmhd\n");
  49.     }
  50.     if( Read( tbild, &depth, 1 ) != 1 )
  51.     {    
  52.         printf("Read error bmhd\n");
  53.     }
  54.     if( Read( tbild, &picture, 1 ) != 1 )
  55.     {    
  56.         printf("Read error bmhd\n");
  57.     }
  58.     if( Read( tbild, &compr, 1 ) != 1 )
  59.     {    
  60.         printf("Read error bmhd\n");
  61.     }
  62.     if( Read( tbild, &picture, 3 ) != 3 )
  63.     {    
  64.         printf("Read error bmhd\n");
  65.     }
  66.  
  67.     if( Read( tbild, &aspx, 1 ) != 1 )
  68.     {    
  69.         printf("Read error bmhd\n");
  70.     }
  71.     if( Read( tbild, &aspy, 1 ) != 1 )
  72.     {    
  73.         printf("Read error bmhd\n");
  74.     }
  75.  
  76.     /*printf("chunksize %d\n", chunksize);*/
  77.     Seek( tbild, chunksize-16, OFFSET_CURRENT );
  78. }
  79.  
  80. void iffcmap( void )
  81. {
  82.     int a;
  83.     BYTE *colo;
  84.  
  85.     chunksread = chunksread | 2;
  86.     ncol = (int) chunksize/3;
  87.     if (ncol<=256)
  88.     {
  89.         colo=&colors[ 0 ];
  90.         for (a=0;a<ncol;a++)
  91.         {
  92.             if( Read( tbild, colo, 3 ) != 3 )
  93.             {    
  94.                 printf("Read error cmap\n");
  95.             }
  96.             colo = colo + 4;
  97.             SetRGB4( &my_view_port, a, colors[ a*4 ], colors[ a*4+1 ], colors[ a*4+2 ] );
  98.         }
  99.         Seek( tbild, chunksize-ncol*3, OFFSET_CURRENT );
  100.     }
  101.     else
  102.     {
  103.         printf("zu viele farben\n");
  104.     }
  105. }
  106.  
  107. void iffcamg( void )
  108. {
  109.     chunksread = chunksread | 4;
  110.     if( Read( tbild, &camg, 4 ) != 4 )
  111.     {    
  112.         printf("Read error bmhd\n");
  113.     }
  114. }
  115.  
  116. void zeilelesen( void )
  117. {
  118.     UWORD a, b;
  119.     UBYTE aa;
  120.  
  121.     bprow=bytezeile;
  122.     if (compr==1)
  123.     {
  124.         while (bprow>0)
  125.         {
  126.             if( Read( tbild, &aa, 1 ) != 1 )
  127.             {    
  128.                 printf("Read error line (comand)\n");
  129.                 bprow = 0;
  130.             }
  131.             a = aa;
  132.             if ( a<128 )
  133.             {
  134.                 /* ungecruncht */
  135.                 a=a+1;
  136.                 if( Read( tbild, my_bit_map.Planes[ plane ]+line*RWIDTH/8+bytezeile-bprow, a ) != a )
  137.                 {    
  138.                     printf("Read error line\n");
  139.                     bprow = 0;
  140.                 }
  141.                 bprow=bprow-a;
  142.             }
  143.             else if ( a>128 )
  144.             {
  145.                 a=256-a+1;
  146.     
  147.                 if( Read( tbild, &aa, 1 ) != 1 )
  148.                 {    
  149.                     printf("Read error bmhd\n");
  150.                 }
  151.     
  152.                 while( a>0 )
  153.                 {
  154.                     *((UBYTE *) my_bit_map.Planes[ plane ]+line*RWIDTH/8+bytezeile-bprow) = aa;
  155.                     bprow--;
  156.                     a--;
  157.                 }
  158.             }
  159.         }
  160.     }
  161.     else
  162.     {
  163.         /* nicht gecruncht */
  164.         if( Read( tbild, my_bit_map.Planes[ plane ]+line*RWIDTH/8, bytezeile ) != bytezeile )
  165.         {    
  166.             printf("Read error not crunched\n");
  167.         }
  168.     }
  169. }
  170.  
  171. void iffbody( void )
  172. {
  173.     int a;
  174.  
  175.     if ( (chunksread & 4) == 0 )
  176.     {
  177.         camg = 0;
  178.     }
  179.     if (depth<=8)
  180.     {
  181.         bytezscreen = 40;        /*    ;Bytes pro Zeile im Screen*/
  182.         farben=(1<<depth);
  183.  
  184.         bytezeile= ((width+15) & 0xfff0) / 8;
  185.  
  186.         for (line=0;line<height;line++)
  187.         {
  188.             for (plane=0;plane<depth;plane++)
  189.             {
  190.                 zeilelesen();
  191.             }
  192.         }
  193.     }
  194. }
  195.  
  196.  
  197. void getilbm( void )
  198. {
  199.     tbild = Open( "data/shoot_title.lbm", MODE_OLDFILE );
  200.     if( tbild!=NULL )
  201.     {
  202.         if( Read( tbild, &picture, 4 ) != 4 )
  203.         {    
  204.             printf("Read error tbild\n");
  205.         }
  206.  
  207.         if ( (picture[0]=='F') && (picture[1]=='O') && (picture[2]=='R') && (picture[3]=='M'))
  208.         {
  209.             chunksread = 0;
  210.  
  211.             bodygot = 0;
  212.             while( bodygot==0 )
  213.             {
  214.                 if( Read( tbild, &picture, 4 ) != 4 )
  215.                 {    
  216.                     printf("Read error chunk header\n");
  217.                 }
  218.                 if( Read( tbild, &chunksize, 4 ) != 4 )
  219.                 {    
  220.                     printf("Read error chunk size\n");
  221.                 }
  222.  
  223.                 if ((picture[0]=='B') && (picture[1]=='M') && (picture[2]=='H') && (picture[3]=='D'))
  224.                 {
  225.                     iffbmhd();
  226.                 }
  227.                 else if ((picture[0]=='C') && (picture[1]=='M') && (picture[2]=='A') && (picture[3]=='P'))
  228.                 {
  229.                     iffcmap();
  230.                 }
  231.                 
  232.                 else if ((picture[0]=='C') && (picture[1]=='A') && (picture[2]=='M') && (picture[3]=='G'))
  233.                 {
  234.                     iffcamg();
  235.                 }
  236.  
  237.                 else if ((picture[0]=='B') && (picture[1]=='O') && (picture[2]=='D') && (picture[3]=='Y'))
  238.                 {
  239.                     iffbody();
  240.                     bodygot = 1;
  241.                 }
  242.                 else
  243.                 {
  244.                     Seek( tbild, chunksize, OFFSET_CURRENT );
  245.                 }
  246.             }
  247.         }
  248.         else
  249.         {
  250.             printf("file is not an IFF-ILBM picture\n");
  251.         }
  252.  
  253.         Close( tbild );
  254.     }
  255.     else
  256.     {
  257.         printf("Couldn't read title\n");
  258.     }
  259. }
  260.  
  261.  
  262.  
  263.